import time
from selenium import webdriver

driver = webdriver.Chrome()
# driver.maximize_window()
driver.get("https://the-internet.herokuapp.com/login")

INPUT_USERNAME = ("id", "username")
INPUT_PASSWORD = ("id", "password")
BUTTON_SUBMIT = ("xpath", "//i[contains(text(),'Login')]")
BUTTON_LOGOUT = ("xpath", "//a[@href='/logout']")

fill_username = driver.find_element(*INPUT_USERNAME)
fill_password = driver.find_element(*INPUT_PASSWORD)
submit_button = driver.find_element(*BUTTON_SUBMIT)

fill_username.clear()
assert fill_username.get_attribute("value") == ""
fill_username.send_keys("tomsmith")
assert fill_username.get_attribute("value") == "tomsmith"

fill_password.clear()
assert fill_password.get_attribute("value") == ""
fill_password.send_keys("SuperSecretPassword!")
assert fill_password.get_attribute("value") == "SuperSecretPassword!"
submit_button.click()

logout_button = driver.find_element(*BUTTON_LOGOUT)

try:
    time.sleep(2)
    assert driver.current_url == "https://the-internet.herokuapp.com/secure"
    assert logout_button.is_displayed()
except:
    print("Ошибка авторизации")
